﻿using Application.MainModule.StatesManagement;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Domain.MainModule.States;
using Domain.MainModule.Entities;

using Infraestructure.CrossCutting.IoC;

namespace Application.MainModule.Tests
{
    /// <summary>
    ///This is a test class for StateManagementServiceTest and is intended
    ///to contain all StateManagementServiceTest Unit Tests
    ///</summary>
    [TestClass()]
    public class StateManagementServiceTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///A test for AddState
        ///</summary>
        [TestMethod()]
        public void AddState_Invoke_Test()
        {
            //Arrange
            IStateManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IStateManagementService>();
            State state = new State()
                     {
                         StateId = Guid.Parse("ABCDF456-1234-BBFF-AAFF-AAAACCBBBBBB"),
                         Name = "test state"
                     };
            State result = null;
            
            //Act
            target.AddState(state);

            //Assert
            result = target.FindStateByName("test state");
            Assert.IsNotNull(result);
            Assert.AreEqual("test state", result.Name);
        }

        /// <summary>
        ///A test for ChangeState
        ///</summary>
        [TestMethod()]
        public void ChangeState_Invoke_Test()
        {
            //Arrange
            IStateManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IStateManagementService>();
            string stateName = "state 01";
            Guid newCountryId = Guid.NewGuid();
            State state = null;
            State result = null;

            //Act
            state = target.FindStateByName(stateName);
            state.CountryId = newCountryId;
            target.ChangeState(state);

            //Assert
            result = target.FindStateByName(stateName);
            Assert.IsNotNull(result);
            Assert.AreEqual(newCountryId, result.CountryId);
        }

        /// <summary>
        ///A test for FindStateByName
        ///</summary>
        [TestMethod()]
        public void FindStateByNameTest()
        {
            //Arrange
            IStateManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IStateManagementService>();
            string stateName = "state 01";
            State state = null;

            //Act
            state = target.FindStateByName(stateName);

            //Assert
            Assert.IsNotNull(state);
            Assert.AreEqual(stateName, state.Name);
        }
    }
}
